<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="120px">
            <el-form-item label="活动名称" prop="activityCode">
                <el-select style="width: 240px" v-model="queryParams.activityCode" placeholder="请选择" size="small">
                <el-option
                v-for="dict in activitiesTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
                />
                </el-select>
            </el-form-item>
            <el-form-item label="用户手机号" prop="mobilePhone">
                <el-input
                    v-model="queryParams.mobilePhone"
                    placeholder="请输入手机号"
                    clearable
                    size="small"
                    style="width: 240px"
                />
            </el-form-item>
            <el-form-item label="状态" prop="status">
                <el-select style="width: 240px" v-model="queryParams.status" placeholder="请选择" clearable size="small">
                <el-option
                v-for="dict in activitiesStatusOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
                />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button type="primary" size="mini" @click="handleAdd">添加白名单</el-button>
            </el-form-item>
        </el-form>
        <el-table v-loading="loading" border :data="getActivitiesDetails" style="margin-left:52px;width:901px;">
            <el-table-column label="活动名称" width="100" align="center">
                <template slot-scope="scope">
                <span v-if="scope.row.activityCode=='InviteFriends'">老带新</span>
                <span v-if="scope.row.activityCode=='PORTPUSHHOU'">一键发房</span>
                </template>
            </el-table-column>
            <el-table-column label="手机号" width="150" align="center">
                <template slot-scope="scope">
                <!-- <span>{{ scope.row.mobilePhone | showTxt }}</span> -->
                <span>{{ scope.row.mobilePhone }}</span>
                </template>
            </el-table-column>
            <el-table-column label="创建人" width="150" align="center">
                --
            </el-table-column>
            <el-table-column label="创建时间" width="200" prop="num" align="center"> 
                <template slot-scope="scope">
                <!-- <span>{{ scope.row.createTime | rounding }}</span> -->
                <span>{{ scope.row.createTime }}</span>
                </template>
            </el-table-column>
            <el-table-column label="状态" width="100" color="blue" align="center">
                <template slot-scope="scope">
                <span v-if="!scope.row.deleted">有效</span>
                <span v-if="scope.row.deleted">无效</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                <el-button
                    v-if="!scope.row.deleted"
                    size="mini"
                    type="text"
                    icon="el-icon-delete"
                    @click="updateWhiteMobileStatus(scope.row)"
                    v-hasPermi="['reviewActivities:activities:edit']"
                >作废</el-button>
                </template>
            </el-table-column>
        </el-table> 
        <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.page"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
            />
        <!-- 添加或修改定时任务对话框 -->
        <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="700px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                <el-form-item label="活动类型" prop="activityCode">
                    <el-select style="width: 240px" v-model="queryParams.activityCode" placeholder="请选择" size="small">
                    <el-option
                    v-for="dict in activitiesTypeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                    />
                    </el-select>
                </el-form-item>
            </el-form>
            <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                 <el-form-item label="微信手机号" prop="mobilePhone">
                    <el-input
                        v-model="queryParams.mobilePhone"
                        placeholder="请输入微信手机号"
                        clearable
                        size="small"
                        style="width: 240px"
                        @blur="checkPhone"
                    />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { queryWhiteMobileByPage, add, updateWhiteMobileStatus, verifyWhiteMobileCheck } from "@/api/reviewActivities/activitiesPeople";
export default {
    name: "activitiesPeoples",
    data() {
        return {
            form:'',
            rules:'',
            loading: false,
            yqTime: [],
            // 审核状态数据字典
            activitiesTypeOptions: [],
            // 活动类型
            activitiesStatusOptions: [],
            //  状态
            queryParams: { 
                page: 1,
                pageSize: 20,
                mobilePhone:undefined,//用户手机号
                activityCode:'InviteFriends',  //活动类型
                status:undefined,  //状态
            },
            // value: 'activityCode',
             getActivitiesDetails: [],
            // 查询参数
            // 总条数
            total: 0,
            title: "",
            // 是否显示弹出层
            open: false,
            // 是否显示详细弹出层
        }
    },
    created() {
        this.getType();
        this.getSatus();
        this.getList();
    },
    methods: {
         //活动类型
      getType() {
        this.activitiesTypeOptions=[{'dictValue':'InviteFriends','dictLabel':'老拉新'},{'dictValue':'PORTPUSHHOU','dictLabel':'一键发房'}];
      },
         //类型
      getSatus() {
        this.activitiesStatusOptions=[{'dictValue':'0','dictLabel':'有效'},{'dictValue':'1','dictLabel':'无效'}];
      },
       //查询活动审核列表
      getList(){
        this.loading = true;
        queryWhiteMobileByPage(this.queryParams).then(
          response => {
            this.getActivitiesDetails = response.data.content.rows;
            this.total = response.data.content.records;
            this.loading = false;
          }
        );
      },
         /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
       /** 新增按钮操作 */
        handleAdd() {
        this.open = true;
        this.title = "添加白名单";
        },
        // 取消按钮
        cancel() {
        this.open = false;
        },
        // 确定按钮
        submitForm: function(){
            let data = {
                mobilePhone: this.queryParams.mobilePhone,
                activityCode: this.queryParams.activityCode
            }
            verifyWhiteMobileCheck(data).then(
                response => {
                    if(response.data.content){
                        add(data).then(
                            res => {
                                if(res.data.isSuccess){
                                    this.$message(res.data.successMessage);
                                    this.cancel();
                                    this.reset();
                                    this.handleQuery();
                                }
                            }
                        )
                    }else {
                        this.$message('白名单已存在');
                    }
                }
            )
            // add(data)
        },
        // 重置
        reset(){
            this.queryParams={
                page:1,
                pageSize: 20,
                activityCode:'InviteFriends',  //活动类型
                mobilePhone:undefined,//用户手机号
                status:undefined,  //状态
            }
        },
        checkPhone(){
            let phone = this.queryParams.mobilePhone;
            if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone))){ 
                this.reset();
                alert("手机号码有误，请重填");  
                return false; 
            } 
        },
        updateWhiteMobileStatus(row){
            let id = row.id;
            let data = {
                id
            }
            updateWhiteMobileStatus(data).then(
                response => {
                    if(response.data.isSuccess)
                    this.$message('已作废');
                    // this.reset();
                    this.queryParams.mobilePhone=undefined;
                    this.getList();
                }
            )
        },
    }
}
</script>